<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="searchForm">
        <el-form-item>
          <el-input v-model="searchForm.name" placeholder="宠物名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getProdunctOnlineAuditLog">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="pets" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
              style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="product.name" label="服务名称">
      </el-table-column>
      <el-table-column prop="state" label="审核状态">
        <template scope="scope">
          <span v-if="scope.row.state==0" style="color: red">失败</span>
          <span v-if="scope.row.state!=0" style="color: green">成功</span>
        </template>
      </el-table-column>
      <el-table-column prop="auditId" label="审核人">
        <template scope="scope">
          <span v-if="scope.row.auditId==null" style="color: red">系统审核</span>
          <span v-if="scope.row.auditId != null" style="color: green">{{scope.row.employee.username}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="auditTime" label="审核时间">
      </el-table-column>
      <el-table-column prop="note" label="备注">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template scope="scope">
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size=pageSize :total="totals"
                     style="float:right;">
      </el-pagination>
    </el-col>

    <!--编辑 新增 界面-->
    <el-dialog :title="title" :visible.sync="editFormVisible" :close-on-click-modal="false">

      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
        <el-form-item label="品种名称" prop="name">
          <el-input v-model="editForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="品种描述" prop="name">
          <el-input v-model="editForm.description" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="宠物类型">
          <div class="block">
            <el-cascader
                v-model="editForm.pid"
                :options="petOnlineAuditLogs"
                :props="{ checkStrictly: true,
                  value:'id',
                  label:'name'
                  }"
                clearable></el-cascader>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>



export default {
  data() {
    return {
      petOnlineAuditLogs:null,
      pageSize: 10,
      fileList: [],
      title: '',
      searchForm: {
        name: ''
      },
      pets: [],
      totals: 0,
      page: 1,
      listLoading: false,
      sels: [],//列表选中列

      editFormVisible: false,//编辑界面是否显示
      editLoading: false,
      editFormRules: {
        name: [
          {required: true, message: '请输入品种名称', trigger: 'blur'}
        ]
      },
      //编辑界面数据
      editForm: {
        name:'',
        description:'',
        pid:null,

      },
      addFormVisible: false,//新增界面是否显示
      addLoading: false,
      addFormRules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ]
      }

    }
  },
  methods: {

    handleCurrentChange(val) {
      this.page = val;
      this.getProdunctOnlineAuditLog();
    },
    //获取宠物类型列表
    getProdunctOnlineAuditLog() {
      let para = {
        currentPage: this.page,
        pageSize : this.pageSize,
        keyWord: this.searchForm.name
      };
      //打开加载的效果
      this.listLoading = true;
      //
      this.$http.post("/productOnlineAuditLog/list", para).then(res => {
        this.pets = res.data.rows;
        this.totals = res.data.totals;
        //关闭加载的效果
        this.listLoading = false;
        console.debug(res);
      });
    },
    //删除
    handleDel: function (index, row) {
      console.log("打印一下" + row.id);
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        //开启加载的模态框
        this.listLoading = true;
        //NProgress.start();
        console.debug(row)
        //后台地址的请求
        this.$http.delete("/petOnlineAuditLog/" + row.id).then((res) => {
          this.listLoading = false;
          console.debug(res);
          if (res.data.success) {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
          }

          this.getProdunctOnlineAuditLog();
        });
      }).catch(() => {

      });
    },
    //显示编辑界面
    handleEdit: function (index, row) {

      this.editFormVisible = true;

      //回显
      console.debug(row)
      console.debug(this.editForm)
      this.editForm = Object.assign({}, row);

      //会显示详情

      //图片回显
    },
    //显示新增界面
    handleAdd: function () {
      this.title = '新增宠物';
      //初始化表单字段-利用的双向绑定的特性
      // this.getProdunctOnlineAuditLog();
      this.editForm = {
        pid:null,
        name:'',
        description:'',

      };
      //打开弹出框
      this.editFormVisible = true;


    },
    //编辑
    editSubmit: function () {
      //验证当前的表单是否符合验证规则
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            //把表单的数据组装为json
            let para = Object.assign({}, this.editForm);

            // 处理宠物类型树数据
            para.pid = para.pid[para.pid.length - 1]
            console.log("sdfafdsfs")
            console.log(para)
            //para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
            this.$http.put('/petOnlineAuditLog', para).then((res) => {
              this.editLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              //重置表单-调用现成的方法
              this.$refs['editForm'].resetFields();
              //关闭 加载框
              this.editFormVisible = false;
              //重新刷新页面数据
              this.getProdunctOnlineAuditLog();
            });
          });
        }
      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id);
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = {ids: ids};
        this.$http.post('/productOnlineAuditLog/dels', ids).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getProdunctOnlineAuditLog();
        });
      }).catch(() => {

      });
    }
  },
  mounted() {
    //当页面加载完以后。执行的方法
    this.getProdunctOnlineAuditLog();
    
  }
}

</script>

<style scoped>

</style>